package ConnDatabase;
import java.sql.*;
public class ConnPropertyDatabase{
    String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String sConnStr = "jdbc:odbc:Propertydatabase";
    Connection conn = null;
    ResultSet rs = null;
	 Statement stmt =null;
	boolean transactionFlag = true ;

    public ConnPropertyDatabase()  {
  try {
            Class.forName(sDBDriver);
			setConnection();
			stmt=conn.createStatement();
  }
  catch(java.lang.ClassNotFoundException e) {
   System.err.println("ConnDatabase(): " + e.getMessage());
 }
 catch(SQLException ex){
   System.err.println("ConnDatabase(): " + ex.getMessage());
   }
    }

    public int executeUpdate(String sql) throws SQLException{
     
      //   conn = DriverManager.getConnection(sConnStr);
        // Statement stmt = conn.createStatement();
         int num=stmt.executeUpdate(sql);
		 return num;
         }

    
    public ResultSet executeQuery(String sql) throws SQLException{
     rs = null;
     //    conn = DriverManager.getConnection(sConnStr);
      //   Statement stmt = conn.createStatement();
         rs = stmt.executeQuery(sql);
         return rs;
    }

public void setConnection() throws SQLException{
conn = DriverManager.getConnection(sConnStr);
}
	
public void startTransaction()throws SQLException{
   transactionFlag=false;
//   transaction flag = false
//   dont allow autocommit
    conn.setAutoCommit(transactionFlag);
   }
   
  public void endTransaction() throws SQLException{
   transactionFlag=true;
   conn.setAutoCommit(transactionFlag);
    } 
	
public boolean isAutocommit() {
    return transactionFlag ;
  }
	
	
public void commit() throws SQLException {
      if (isAutocommit()==false){
          conn.commit();
					System.out.println("commit");
					}
	}
  public void rollback() throws SQLException {
      if (isAutocommit()==false)
          conn.rollback();
  }

}






